<?php

namespace app\index\controller;

use app\index\model\Index as ModelIndex;
use frame\lib\Db;

class Index extends Base
{
  
    public function index()
    {
        $this->view('index');
    }
    public function main()
    {
        $main = ModelIndex::main();
        $this->view('main', ['data' => $main]);
    }
    // 签到(连续)排行
    public function signRand()
    {
        $list = Db::name('sign')->limit(10)->where(['user_id' => $this->uid])->order('total desc')->select();
        success($list);
    }
    // 用户积分排行
    public function userScoreRand()
    {
        $list = Db::name('user')->limit(10)->field('id , username ,score')->where(['user_id' => $this->uid])->order('score desc')->select();
        success($list);
    }
    public function inlineUser()
    {
        $list = Db::name('user')->field('id , username , score , vip_time , last_login_time')->where(['user_id' => $this->uid])->select();
        $n = 0;
        $user = [];
        foreach ($list as $k => $v) {
            if (date('d', getTime(3, $v['last_login_time'])) == date('d', time())) {
                if (date('H', getTime(3, $v['last_login_time'])) >= date('H', time()) - 3) {
                    $n++;
                    $user[] = $v;
                }
            }
        }
        success($user);
    }
}
